package com.jinmdz.fmis.mapper.mapper.provider;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;
import com.jinmdz.fmis.mapper.entity.CremationFurnaceRefuelEntity;

/**
 * 火化炉加油记录表Provider
 * 
 * @author generator
 * @date 2020-08-23 18:11
 */
public class CremationFurnaceRefuelProvider {

    /**
     * 增加CremationFurnaceRefuel
     * 
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-08-23 18:11
     */
    public String insertCremationFurnaceRefuel(@Param("entity") CremationFurnaceRefuelEntity entity) {
        return new SQL() {
            {
                INSERT_INTO(" cremation_furnace_refuel ");

                if (entity.getDeleted() != null) {
                    VALUES(" deleted ", " #{entity.deleted,jdbcType=TINYINT} ");
                }

                VALUES(" furnace_group_id ", " #{entity.furnaceGroupId,jdbcType=INTEGER} ");
                VALUES(" old_number ", " #{entity.oldNumber,jdbcType=DECIMAL} ");
                VALUES(" refuel_number ", " #{entity.refuelNumber,jdbcType=DECIMAL} ");
                VALUES(" new_number ", " #{entity.newNumber,jdbcType=DECIMAL} ");
                VALUES(" refuel_time ", " #{entity.refuelTime,jdbcType=TIMESTAMP} ");
                VALUES(" funeral_parlour_code ", " #{entity.funeralParlourCode,jdbcType=VARCHAR} ");
                VALUES(" create_user_id ", " #{entity.createUserId,jdbcType=INTEGER} ");

                if (entity.getUnmodified() != null) {
                    VALUES(" unmodified ", " #{entity.unmodified,jdbcType=TINYINT} ");
                }

                VALUES(" modified_user_id ", " #{entity.modifiedUserId,jdbcType=INTEGER} ");
                VALUES(" version ", " unix_timestamp(now()) ");
            }
        }.toString();
    }

    /**
     * 修改CremationFurnaceRefuel
     * 
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-08-23 18:11
     */
    public String updateCremationFurnaceRefuel(@Param("entity") CremationFurnaceRefuelEntity entity) {
        return new SQL() {
            {
                UPDATE(" cremation_furnace_refuel ");

                if (entity.getDeleted() != null) {
                    SET(" deleted = #{entity.deleted,jdbcType=TINYINT} ");
                }

                SET(" furnace_group_id = #{entity.furnaceGroupId,jdbcType=INTEGER} ");
                SET(" old_number = #{entity.oldNumber,jdbcType=DECIMAL} ");
                SET(" refuel_number = #{entity.refuelNumber,jdbcType=DECIMAL} ");
                SET(" new_number = #{entity.newNumber,jdbcType=DECIMAL} ");
                SET(" refuel_time = #{entity.refuelTime,jdbcType=TIMESTAMP} ");
                SET(" funeral_parlour_code = #{entity.funeralParlourCode,jdbcType=VARCHAR} ");

                if (entity.getUnmodified() != null) {
                    SET(" unmodified = #{entity.unmodified,jdbcType=TINYINT} ");
                }

                SET(" modified_user_id = #{entity.modifiedUserId,jdbcType=INTEGER} ");
                SET(" version = unix_timestamp(now()) ");
                WHERE(" id = #{entity.id,jdbcType=INTEGER} ");
                WHERE(" unmodified = 0 ");
                WHERE(" version = #{entity.version,jdbcType=INTEGER} ");
            }
        }.toString();
    }

    /**
     * 查询CremationFurnaceRefuel列表
     * 
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-08-23 18:11
     */
    public String listCremationFurnaceRefuel(@Param("entity") CremationFurnaceRefuelEntity entity) {
        return new SQL() {
            {
                StringBuilder builder = new StringBuilder();
                builder.append(" id,deleted,furnace_group_id,old_number,refuel_number,new_number,refuel_time,funeral_parlour_code,create_user_id,gmt_create,unmodified,modified_user_id,gmt_modified,version ");
                SELECT(builder.toString());
                FROM(" cremation_furnace_refuel ");

                if (entity.getFurnaceGroupId() != null) {
                    WHERE(" furnace_group_id = #{entity.furnaceGroupId,jdbcType=INTEGER} ");
                }

                if (entity.getOldNumber() != null) {
                    WHERE(" old_number = #{entity.oldNumber,jdbcType=DECIMAL} ");
                }

                if (entity.getRefuelNumber() != null) {
                    WHERE(" refuel_number = #{entity.refuelNumber,jdbcType=DECIMAL} ");
                }

                if (entity.getNewNumber() != null) {
                    WHERE(" new_number = #{entity.newNumber,jdbcType=DECIMAL} ");
                }

                if (entity.getRefuelTime() != null) {
                    WHERE(" refuel_time = #{entity.refuelTime,jdbcType=TIMESTAMP} ");
                }

                if (entity.getFuneralParlourCode() != null) {
                    WHERE(" funeral_parlour_code = #{entity.funeralParlourCode,jdbcType=VARCHAR} ");
                }

            }
        }.toString();
    }
}